<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('百度汉字列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>字：</p>
                                <input type="text" name="zi"/>
                            </li>
                            <li>
                                <p>已入库：</p>
                                <select name="status" th:with="type=${@dict.getType('common_support')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary multiple disabled" onclick="batchimport2zi()" shiro:hasPermission="dict:hanyuzi:edit">
                    <i class="fa fa-edit"></i> 批量同步入库
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="dict:hanyuzi:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('dict:hanyuzi:edit')}]];
        var removeFlag = [[${@permission.hasPermi('dict:hanyuzi:remove')}]];
        var statusDatas = [[${@dict.getType('common_support')}]];
        var prefix = ctx + "dict/hanyuzi";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "百度汉字",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'zi', 
                    title : '字'
                },
                {
                    field : 'pinyin', 
                    title : '拼音'
                },
                {
                    field : 'wubi', 
                    title : '五笔'
                },
                {
                    field : 'bushou', 
                    title : '部首'
                },
                {
                    field : 'fzi', 
                    title : '繁体字'
                },
                {
                    field : 'baike', 
                    title : '百科解释',
                    formatter: function(value, row, index) {
                		return $.table.tooltip(value);
                	}
                },
                {
                    field : 'createdTime', 
                    title : '抓取时间'
                },
                {
                    field : 'status', 
                    title : '已入库',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="import2zi(\'' + row.id + '\')"><i class="fa fa-edit"></i>同步到生字库</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function import2zi(id) {
			$.modal.confirm('确这同步拼音和百科解释到生字库吗?', function() {
				$.operate.post(prefix + "/import2zi", { "id": id});
		    })
		}

		function batchimport2zi(){

            var rows = $.table.selectColumns("id");
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确定要同步选中的" + rows.length + "条数据到生字库吗?", function() {
                var data = {"ids": rows.join()};
			    $.operate.post(prefix + "/batchimport2zi", data);
       		})

		}

    </script>
</body>
</html>